libname mynsfg "F:\SLU Desktop\Men";

data mynsfg.LCAaim2;
set mynsfg.LCAaim2;
run;
/**********************STEP 1B: CREATE AND HARD ASSIGN LCA VARIABLE************************************************/
proc LCA data=mynsfg.LCAaim2 outpost=mynsfg.postprob1 outparam=par4 outstderr=err4 outseeds=seed4;
 Title 'LCA round 3 run menbmi categories';
	nclass 3;
	items sexprt2 sexrisk condom2 hltstat2 drink2 drug sti bmi3;
	categories 2 2 2 2 2 2 2 2;
	seed 123456789;
	id caseid;
	nstarts 50;
	maxiter 50000;
	rho prior= 1;
	weight weightvar;
	cluster panelvar;
run;

/********************STEP 1C: MERGING ORIGINAL DATASET WITH POSTERIOR PROBABILITY OUTPUT DATASET************************/

proc print data=mynsfg.postprob1 (obs=50); run; 
/*proc freq data=mydata.LCAaim2; tables kiddos; run;*/


proc sort data=mynsfg.LCAaim2;
by caseid;
proc sort data=mynsfg.postprob1;
by caseid;

data mynsfg.LCA1119aim3;
merge mynsfg.LCAaim2 (in=a) mynsfg.postprob1;
by caseid; if a;
run;

proc contents data=mynsfg.LCA1119aim3;run;

proc freq data=mynsfg.LCA1119aim3; tables best; run;
/****************************************CREATING PHP VARIABLE*****************************************************/

proc format;
value phpx 0="lowest risk"
		   1="substance users"
		   2="sexual risk takers";
value intentcollx 0="definite no"
	              1="definite yes"
				  2="Far or contingent intention"
				  3="indifferent or ambivalent";
label php = "preconception health"
      intentcoll = "future pregnancy intention";
run;
data mynsfg.LCA1119aim3;
set mynsfg.LCA1119aim3;

if best=1 then php=2;
else if best=2 then php=0;
else if best=3 then php=1;
if pregint=0 and certain =0 then intention=0; /* preg_intention 6 categorties*/
else if pregint=1 and certain=1 then intention=1;
else if pregint=1 and certain =0 then intention=2;
else if pregint=2 and certain=0 then intention=2;
else if pregint=0 and certain=1 then intention=3;
else if pregint=2 and certain=1 then intention=3;
else if pregint=1 and certain=2 then intention=4;
else if pregint=0 and certain=2 then intention=4;
else if pregint=2 and certain=2 then intention=5;

if intention=0 then intentcoll=0; /* preg_intention_four categories*/
else if intention=1 then intentcoll=1;
else if intention in (2:3) then intentcoll=2;
else if intention in (4:5) then intentcoll=3;
format php phpx. intentcoll intentcollx.;
run;

ods rtf file="F:\SLU Desktop\Men\Confounding analysis\Aim2_coufounding_Race";
/*****RACE/ETHNICITY******/
/*********************************************************************************/
/*******forward fitting model - RACE ***/

proc surveylogistic data=mynsfg.LCA1119aim3; /**crude model**/
class  hisprace0(ref="0")/ param=ref; /*NHW as baseline category*/
model php(ref="lowest risk") =  hisprace0/ link=glogit; 
weight weightvar;
cluster panelvar;
strata stratvar;
run;

proc surveylogistic data=mynsfg.LCA1119aim3; /*** add age***/
class  hisprace0(ref="0") age(ref="4")/ param=ref; /*NHW as baseline category*/
model php(ref="lowest risk") =  hisprace0 age / link=glogit; 
weight weightvar;
cluster panelvar;
strata stratvar;
run;


proc surveylogistic data=mynsfg.LCA1119aim3; /*** add age, sexage***/
class  hisprace0(ref="0") age(ref="4")sexage(ref="2")/ param=ref; /*NHW as baseline category*/
model php(ref="lowest risk") =  hisprace0 age sexage / link=glogit; 
weight weightvar;
cluster panelvar;
strata stratvar;
run;


proc surveylogistic data=mynsfg.LCA1119aim3; /*** add age, sexage, kids***/
class  hisprace0(ref="0") age(ref="4")sexage(ref="2") kids(ref="3")/ param=ref; /*NHW as baseline category*/
model php(ref="lowest risk") =  hisprace0 age sexage kids / link=glogit; 
weight weightvar;
cluster panelvar;
strata stratvar;
run;

proc surveylogistic data=mynsfg.LCA1119aim3; /*** add age, sexage, kids, union***/
class  hisprace0(ref="0") age(ref="4")sexage(ref="2") kids(ref="3")union3(ref="0")/ param=ref; /*NHW as baseline category*/
model php(ref="lowest risk") =  hisprace0 age sexage kids UNION3 / link=glogit; 
weight weightvar;
cluster panelvar;
strata stratvar;
run;

proc surveylogistic data=mynsfg.LCA1119aim3;/***add age, sexage, kids, union***/ /*fully adjusted model**/
class  hisprace0(ref="0")union3(ref="0") kids(ref="3") age(ref="4") sexage(ref="2") year (ref="2012")/ param=ref; /*NHW as baseline category*/
model php(ref="lowest risk") =  hisprace0 age sexage  kids UNION3 year / link=glogit; 
weight weightvar;
cluster panelvar;
strata stratvar;
run;
ods rtf close;

/*****************************************************************************************
*****************************************************************************************

/******************************EDUCATION STATUS*******************************************/
ods rtf file="F:\SLU Desktop\Men\Confounding analysis\Aim2_coufounding_Education";
proc surveylogistic data=mynsfg.LCA1119aim3; /*** crude model***/
class educ(ref="0")/ param=ref; /*ref= less than HS educ*/
model php(ref="lowest risk") =  educ / link=glogit; 
weight weightvar;
cluster panelvar;
strata stratvar;
run;
proc surveylogistic data=mynsfg.LCA1119aim3; /*** add age***/
class educ(ref="0") age(ref="4")/ param=ref; /*ref= less than HS educ*/
model php(ref="lowest risk") =  educ age / link=glogit; 
weight weightvar;
cluster panelvar;
strata stratvar;
run;


proc surveylogistic data=mynsfg.LCA1119aim3; /*** add age, sexage***/
class  educ(ref="0") age(ref="4")sexage(ref="2")/ param=ref; /*ref= less than HS educ*/
model php(ref="lowest risk") =  educ age sexage / link=glogit; 
weight weightvar;
cluster panelvar;
strata stratvar;
run;


proc surveylogistic data=mynsfg.LCA1119aim3; /*** add age, sexage, kids***/
class  educ(ref="0") age(ref="4")sexage(ref="2") kids(ref="3")/ param=ref; /*ref= less than HS educ*/
model php(ref="lowest risk") =  educ age sexage kids / link=glogit; 
weight weightvar;
cluster panelvar;
strata stratvar;
run;

proc surveylogistic data=mynsfg.LCA1119aim3; /*** add age, sexage, kids, union***/
class  educ(ref="0") age(ref="4")sexage(ref="2") kids(ref="3")union3(ref="0")/ param=ref; /*ref= less than HS educ*/
model php(ref="lowest risk") =  educ age sexage kids UNION3 / link=glogit; 
weight weightvar;
cluster panelvar;
strata stratvar;
run;

proc surveylogistic data=mynsfg.LCA1119aim3;/***add age, sexage, kids, union***/ /*fully adjusted model**/
class  educ(ref="0")union3(ref="0") kids(ref="3") age(ref="4") sexage(ref="2") year (ref="2012")/ param=ref; /*ref= less than HS educ*/
model php(ref="lowest risk") =  educ age sexage  kids UNION3 year / link=glogit; 
weight weightvar;
cluster panelvar;
strata stratvar;


proc surveylogistic data=mynsfg.LCA1119aim3; /**fully adjusted model***/
class educ(ref="0")union3(ref="0") kids(ref="3") age(ref="4") sexage(ref="2")year (ref="2012")/ 
param=ref; /*ref= less than HS educ*/
model php (ref="lowest risk") = educ UNION3 kids age sexage year/ link=glogit; 
weight weightvar;
cluster panelvar;
strata stratvar;
run;
ods rtf close;

ods rtf file="F:\SLU Desktop\Men\Confounding analysis\Aim2_coufounding_Employment";
/*****EMPLOYMENT CONSISTENCY******/

proc surveylogistic data=mynsfg.LCA1119aim3; /*** crude model***/
class workcons2(ref="2")/ param=ref; /*ref= yes stable employment*/
model php(ref="lowest risk") =  workcons2 / link=glogit; 
weight weightvar;
cluster panelvar;
strata stratvar;
run;
proc surveylogistic data=mynsfg.LCA1119aim3; /*** add age***/
class workcons2(ref="2") age(ref="4")/ param=ref; /*ref= yes stable employment*/
model php(ref="lowest risk") =  workcons2 age / link=glogit; 
weight weightvar;
cluster panelvar;
strata stratvar;
run;


proc surveylogistic data=mynsfg.LCA1119aim3; /*** add age, sexage***/
class  workcons2(ref="2") age(ref="4")sexage(ref="2")/ param=ref; /*ref= yes stable employment*/
model php(ref="lowest risk") =  workcons2 age sexage / link=glogit; 
weight weightvar;
cluster panelvar;
strata stratvar;
run;


proc surveylogistic data=mynsfg.LCA1119aim3; /*** add age, sexage, kids***/
class  workcons2(ref="2") age(ref="4")sexage(ref="2") kids(ref="3")/ param=ref; /*ref= yes stable employment*/
model php(ref="lowest risk") =  workcons2 age sexage kids / link=glogit; 
weight weightvar;
cluster panelvar;
strata stratvar;
run;

proc surveylogistic data=mynsfg.LCA1119aim3; /*** add age, sexage, kids, union***/
class workcons2(ref="2") age(ref="4")sexage(ref="2") kids(ref="3")union3(ref="0")/ param=ref; /*ref= yes stable employment*/
model php(ref="lowest risk") =  workcons2 age sexage kids UNION3 / link=glogit; 
weight weightvar;
cluster panelvar;
strata stratvar;
run;

proc surveylogistic data=mynsfg.LCA1119aim3;/***add age, sexage, kids, union***/ /*fully adjusted model**/
class  workcons2(ref="2") union3(ref="0") kids(ref="3") age(ref="4") sexage(ref="2") year (ref="2012")/ param=ref; /*ref= yes stable employment*/
model php(ref="lowest risk") =  workcons2 age sexage  kids UNION3 year / link=glogit; 
weight weightvar;
cluster panelvar;
strata stratvar;


proc surveylogistic data=mynsfg.LCA1119aim3;/**fully adjusted model***/
class workcons2(ref="2")union3(ref="0") kids(ref="3") age(ref="4") sexage(ref="2")year (ref="2012")/ 
param=ref; /*ref= yes stable employment*/
model php (ref="lowest risk") = workcons2 UNION3 kids age sexage year/ link=glogit; 
weight weightvar;
cluster panelvar;
strata stratvar;
run;

ods rtf close

ods rtf file="F:\SLU Desktop\Men\Confounding analysis\Aim2_coufounding_Insurance";
/*****INSURANCE STATUS******/

proc surveylogistic data=mynsfg.LCA1119aim3;/**crude model*/
class insur2(ref="1")/ param=ref; /*ref= insured*/
model php (ref="lowest risk") = insur2 / link=glogit; 
weight weightvar;
cluster panelvar;
strata stratvar;
run;

proc surveylogistic data=mynsfg.LCA1119aim3; /*** add age***/
class insur2(ref="0") age(ref="4")/ param=ref; /*ref= yes stable employment*/
model php(ref="lowest risk") =  insur2 age / link=glogit; 
weight weightvar;
cluster panelvar;
strata stratvar;
run;


proc surveylogistic data=mynsfg.LCA1119aim3; /*** add age, sexage***/
class  insur2(ref="0") age(ref="4")sexage(ref="2")/ param=ref; /*ref= yes stable employment*/
model php(ref="lowest risk") =  insur2 age sexage / link=glogit; 
weight weightvar;
cluster panelvar;
strata stratvar;
run;


proc surveylogistic data=mynsfg.LCA1119aim3; /*** add age, sexage, kids***/
class  insur2(ref="0") age(ref="4")sexage(ref="2") kids(ref="3")/ param=ref; /*ref= yes stable employment*/
model php(ref="lowest risk") =  insur2 age sexage kids / link=glogit; 
weight weightvar;
cluster panelvar;
strata stratvar;
run;

proc surveylogistic data=mynsfg.LCA1119aim3; /*** add age, sexage, kids, union***/
class insur2(ref="0") age(ref="4")sexage(ref="2") kids(ref="3")union3(ref="0")/ param=ref; /*ref= yes stable employment*/
model php(ref="lowest risk") =  insur2 age sexage kids UNION3 / link=glogit; 
weight weightvar;
cluster panelvar;
strata stratvar;
run;
proc surveylogistic data=mynsfg.LCA1119aim3; /*** add age, sexage, kids, union, year***//**fully adjusted model***/
class insur2(ref="0") union3(ref="0") kids(ref="3") age(ref="4") sexage(ref="2") year(ref="2012")/ param=ref;/*ref= insured*/
model php (ref="lowest risk") = insur2 UNION3 kids age sexage year/ link=glogit; 
weight weightvar;
cluster panelvar;
strata stratvar;
run;

ods rtf close;
